package com.dongdongshop.consumer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.service.EsService;
import com.dongdongshop.service.ItemService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @Description
 * @ClassName EsConsumer
 * @Author RC
 * @date 2021.01.01 23:17
 */
@Component
@RocketMQMessageListener(topic = "approvedSendSuccess",messageModel = MessageModel.BROADCASTING,consumerGroup = "dongdongshop_producer")
public class EsConsumer implements RocketMQListener<Long[]> {
    @Reference(timeout = 10000,check = false)
    private ItemService itemService;
    @Reference(timeout = 10000,check = false)
    private EsService esService;

    @Override
    public void onMessage(Long[] goodsIds) {
        for (Long goodsId : goodsIds) {
            List<TbItem> itemList = itemService.findItemById(goodsId);
            try {
                esService.addSource(itemList);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
